﻿@namespace iPanel.Components

@using iPanel.Components.Dialogs
@using iPanel.Resources

@inject IStringLocalizer<ControlsStrings> Loc
@inject IStringLocalizer<iPanel.Resources.Dialogs> DialogsLoc

@if (!string.IsNullOrWhiteSpace(ExceptionText))
{
    <FluentButton Appearance="Appearance.Lightweight"
                  OnClick="OnExceptionDetailsClickedAsync"
                  Title="@Loc[nameof(ControlsStrings.ExceptionDetailsTitle)]"
                  Class="exception-details-button">
        <FluentIcon Icon="Icons.Filled.Size16.DocumentError"
                    Color="Color.Accent" />
    </FluentButton>
}

@code {
    [Parameter, EditorRequired]
    public required string ExceptionText { get; set; }

    [CascadingParameter]
    public required ViewportInformation ViewportInformation { get; init; }

    [Inject]
    public required IDialogService DialogService { get; init; }

    private async Task OnExceptionDetailsClickedAsync()
    {
        await TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, DialogsLoc, Loc[nameof(ControlsStrings.ExceptionDetailsTitle)], ExceptionText, containsSecret: false);
    }
}
